import { MockMethod } from 'vite-plugin-mock';
import { resultSuccess, resultFeedSuccess } from '../_util';
import { Random } from 'mockjs';
import { sampleSize, random } from 'lodash-es';

const categoryBriefs = [
  {
    category_id: Random.increment(),
    category_name: '推荐',
    category_url: 'recommend',
  },
  {
    category_id: Random.increment(),
    category_name: '关注',
    category_url: 'following',
  },
  {
    category_id: Random.increment(),
    category_name: '热门',
    category_url: 'hot',
  },
  {
    category_id: Random.increment(),
    category_name: 'GameFi',
    category_url: 'game_fi',
  },
  {
    category_id: Random.increment(),
    category_name: 'DAO',
    category_url: 'dao',
  },
  {
    category_id: Random.increment(),
    category_name: 'DeFi',
    category_url: 'de_fi',
  },
  {
    category_id: Random.increment(),
    category_name: 'SocialFi',
    category_url: 'social_fi',
  },
  {
    category_id: Random.increment(),
    category_name: 'Blockchain',
    category_url: 'blockchain',
  },
  {
    category_id: Random.increment(),
    category_name: 'Bitcoin',
    category_url: 'bitcoin',
  },
  {
    category_id: Random.increment(),
    category_name: 'NFT',
    category_url: 'nft',
  },
  {
    category_id: Random.increment(),
    category_name: 'ETH',
    category_url: 'eth',
  },
];

const adverts = [
  {
    id: '@increment()',
    url: 'https://juejin.cn/pin/topic/7202454509627375655',
    picture: 'https://loremflickr.com/778/82/blockchain?lock=@natural(1,10)',
  },
  {
    id: '@increment()',
    url: 'https://juejin.cn/pin/7205122038318628923',
    picture: 'https://loremflickr.com/778/82/blockchain?lock=lock=@natural(1,10)',
  },
  {
    id: '@increment()',
    url: 'https://juejin.cn/video/7202149403342143520?utm_source=web_banner&utm_medium=banner&utm_campaign=xiaoce_nuxt3_20230301',
    picture: 'https://loremflickr.com/778/82/blockchain?lock=lock=@natural(1,10)',
  },
];

const banners = (() => {
  const result: any[] = [];
  for (let index = 0; index < 5; index++) {
    result.push({
      id: index,
      avatar: 'https://loremflickr.com/480/480/avatar?lock=' + Random.increment(),
      cover_image: Random.pick([
        'https://loremflickr.com/778/568/life?lock=' + Random.increment(),
        'https://loremflickr.com/778/568/travel?lock=' + Random.increment(),
      ]),
      title: '@ctitle()',
      brief_content: '@cparagraph()',
      time: `@datetime(yyyy-MM-dd HH:mm)`,
      like: '@natural(0, 1000)',
      collect: '@natural(0, 1000)',
      replay: '@natural(0, 1000)',
      view: '@natural(0, 1000)',
      read: '@natural(0, 1000)',
      status: Random.pick(['all', 'published', 'rejected']),
      read_time: '@natural(0, 120)',
      name: '@cname()',
      tags: sampleSize(['DAO', 'GameFi', 'SocialFi', '前端', '后端'], random(1, 3)),
    });
  }
  return result;
})();

const allFeed = (() => {
  const result: any[] = [];
  for (let index = 0; index < 20; index++) {
    result.push({
      id: index,
      avatar: 'https://loremflickr.com/480/480/avatar?lock=' + Random.increment(),
      cover_image: Random.pick([
        '',
        'https://loremflickr.com/1280/854/life?lock=' + Random.increment(),
        'https://loremflickr.com/1280/854/computer?lock=' + Random.increment(),
      ]),
      title: '@ctitle()',
      brief_content: '@cparagraph()',
      time: `@datetime(yyyy-MM-dd HH:mm)`,
      like: '@natural(0, 1000)',
      collect: '@natural(0, 1000)',
      replay: '@natural(0, 1000)',
      view: '@natural(0, 1000)',
      read: '@natural(0, 1000)',
      status: Random.pick(['all', 'published', 'rejected']),
      read_time: '@natural(0, 120)',
      name: '@cname()',
      tags: sampleSize(['DAO', 'GameFi', 'SocialFi', '前端', '后端'], random(1, 3)),
      desc: '@cparagraph()',
    });
  }
  return result;
})();

const followers = (() => {
  const result: any[] = [];
  for (let index = 0; index < 5; index++) {
    result.push({
      id: index,
      avatar: 'https://loremflickr.com/480/480/avatar?lock=' + Random.increment(),
      cover_image: Random.pick([
        '',
        'https://loremflickr.com/1280/854/life?lock=' + Random.increment(),
        'https://loremflickr.com/1280/854/computer?lock=' + Random.increment(),
      ]),
      title: '@ctitle()',
      brief_content: '@cparagraph()',
      time: `@datetime(yyyy-MM-dd HH:mm)`,
      like: '@natural(0, 1000)',
      collect: '@natural(0, 1000)',
      replay: '@natural(0, 1000)',
      view: '@natural(0, 1000)',
      read: '@natural(0, 1000)',
      status: Random.pick(['all', 'published', 'rejected']),
      read_time: '@natural(0, 120)',
      name: '@cname()',
      tags: sampleSize(['DAO', 'GameFi', 'SocialFi', '前端', '后端'], random(1, 3)),
      desc: '@cparagraph()',
    });
  }
  return result;
})();

const articles = (() => {
  const result: any[] = [];
  for (let index = 0; index < 5; index++) {
    result.push({
      id: index,
      avatar: 'https://loremflickr.com/480/480/avatar?lock=' + Random.increment(),
      cover_image: Random.pick([
        '',
        'https://loremflickr.com/1280/854/life?lock=' + Random.increment(),
        'https://loremflickr.com/1280/854/computer?lock=' + Random.increment(),
      ]),
      title: '@ctitle()',
      brief_content: '@cparagraph()',
      time: `@datetime(yyyy-MM-dd HH:mm)`,
      like: '@natural(0, 1000)',
      collect: '@natural(0, 1000)',
      replay: '@natural(0, 1000)',
      view: '@natural(0, 1000)',
      read: '@natural(0, 1000)',
      status: Random.pick(['all', 'published', 'rejected']),
      read_time: '@natural(0, 120)',
      name: '@cname()',
      tags: sampleSize(['DAO', 'GameFi', 'SocialFi', '前端', '后端'], random(1, 3)),
      desc: '@cparagraph()',
    });
  }
  return result;
})();

export default [
  {
    url: '/basic-api/recommend/query_category_briefs',
    timeout: 500,
    method: 'post',
    response: () => {
      return resultSuccess(categoryBriefs);
    },
  },
  {
    url: '/basic-api/recommend/query_adverts',
    timeout: 500,
    method: 'post',
    response: () => {
      return resultSuccess(adverts);
    },
  },
  {
    url: '/basic-api/recommend/query_banners',
    timeout: 500,
    method: 'post',
    response: () => {
      return resultSuccess(banners);
    },
  },
  {
    url: '/basic-api/recommend/all_feed',
    timeout: 1000,
    method: 'post',
    response: () => {
      return resultFeedSuccess(allFeed);
    },
  },
  {
    url: '/basic-api/recommend/followers',
    timeout: 1000,
    method: 'post',
    response: () => {
      return resultFeedSuccess(followers);
    },
  },
  {
    url: '/basic-api/recommend/articles',
    timeout: 1000,
    method: 'post',
    response: () => {
      return resultFeedSuccess(articles);
    },
  },
] as MockMethod[];
